<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Users;
class LoginController extends Controller
{	

	//登陆页面
    public function login(){
    	return view('admin.login');
    }

    //登陆
    public function doLogin(Request $request){
    	// echo 111;
    	$username = $request->username;
    	$password = md5($request->password);
    	// var_dump($password);die;
    	$model = new Users();
    	$data=$model->login($username);
    	// dd($data);die;
    	if(!empty($data)){
    		if($data->password == $password){
    			// echo $data->password;
    			$request->session()->put('users',$data);
    			return redirect('admin');
    		}else{
    			return back()->with('msg',"用户名或密码错误");
    		}
    	}else{
    		return back()->with('msg',"用户名不存在");
    		// return view('admin/login')->with('msg','用户名不存在');
    	}
    }
}
